package com.homedo.odin.solution.enumcode.specification;

import java.util.Arrays;
import lombok.Getter;

/**
 * 订单业务类型
 * @author yanghaohao
 *
 */
@Getter
public enum OrderBusinessTypeEnum {

  SOLUTION(1, "方案"), SPECIFICATION(2, "行业规范");

  private Integer dbValue;
  private String displayValue;

  OrderBusinessTypeEnum(Integer dbValue, String displayValue) {
    this.displayValue = displayValue;
    this.dbValue = dbValue;
  }

  /**
   * 判断是否存在枚举dbValue
   */
  public static boolean dbValueExist(Integer dbValue) {
    return Arrays.stream(OrderBusinessTypeEnum.values()).anyMatch(obj -> obj.getDbValue().equals(dbValue));
  }

  /**
   * 判断是否存在枚举displayValue
   */
  public static boolean displayValueExist(String displayValue) {
    return Arrays.stream(OrderBusinessTypeEnum.values()).anyMatch(obj -> obj.getDisplayValue().equals(displayValue));
  }

  /**
   * 匹配获取对应的DisplayValue
   */
  public static String getExistDisplayValue(Integer dbValue) {
    return Arrays.stream(OrderBusinessTypeEnum.values()).filter(obj -> obj.getDbValue().equals(dbValue))
        .map(obj -> obj.getDisplayValue()).findFirst().orElse(null);
  }

}
